package com.tjw.ec.upms.controller;

import com.tjw.ec.common.core.util.PageUtils;
import com.tjw.ec.common.core.util.R;
import com.tjw.ec.upms.api.entity.UserGroupEntity;
import com.tjw.ec.upms.service.UserGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 控制动作层： 用户组表
 *
 * @author T-junwen
 * @email t-junwen@foxmail.com
 * @date 2019-07-27 17:28:58
 */
@RestController
@RequestMapping("usergroup")
public class UserGroupController {

    @Autowired
    private UserGroupService userGroupService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = userGroupService.queryPage(params);
        return R.data(page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{userGroupId}")
    public R info(@PathVariable("userGroupId") Integer userGroupId) {
            UserGroupEntity userGroup = userGroupService.getById(userGroupId);
        return R.data(userGroup);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody UserGroupEntity userGroup) {
            userGroupService.save(userGroup);
        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody UserGroupEntity userGroup) {
            userGroupService.updateById(userGroup);
        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestParam Integer[]ids) {
            userGroupService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
